﻿using Flurl.Http;
using Flurl.Http.Configuration;
using Microsoft.Extensions.Options;
using Vin.Extension.FlurlHttpClient.Service;
using Vin.Extension.Framework.Map.Tencent.Options;
using Vin.Tool.AspNetCore.Service;
using Vin.Tool.Attributes;

namespace Vin.Extension.Framework.Map.Tencent.Service;

public class BaseTencentMapService : VinBaseService
{
    public const string BaseUrl = "https://apis.map.qq.com";

    [Inject] protected readonly IOptionsMonitor<TencentMapOption> _tencentMapOption = null!;

    protected TencentMapOption Option => _tencentMapOption.CurrentValue;

    [Inject] protected readonly VinFlurlClient _vinFlurlClient = null!;

    protected IFlurlClient FlurlClient => _vinFlurlClient.FlurlClient;

    public BaseTencentMapService()
    {
        _vinFlurlClient.FlurlClient.BaseUrl = BaseUrl;
    }

    public IFlurlRequest CreateRequest(string path)
    {
        if (string.IsNullOrEmpty(Option.Key)) throw new Exception("未配置腾讯地图Key. 路径（VinMap:Tencent）");
        return FlurlClient.Request(path).SetQueryParam("key", Option.Key);
    }
}